<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page.sync="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               v-model="form"
               ref="crud"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @row-del="rowDel"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
      <template slot="menuLeft">
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   plain
                   v-if="permission.simp105003_delete"
                   @click="handleDelete">删 除
        </el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
  import {getList, getDetail, add, update, remove} from "@/api/demo/simp105003";
  import {mapGetters} from "vuex";

  export default {
    data() {
      return {
        form: {},
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        option: {
          headerAlign: 'center',    //列字段局中
          // align: 'center',       //数据值局中
          menu:false,     //取消显示操作栏
          addBtn:false,   //添加按钮隐藏
          searchSize: "small",//搜索控件的大小small/mini
          index: true,//是否显示表格序号（根据分页会自动计算，比如每页10行，到了第二页就会从11开始记数）
          indexLabel: "id",//序号的标题
          selection:false, //取消多选框
          stripe:true,    //显示斑马纹
          height:'auto',
          calcHeight: 30,
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          viewBtn: true,
          dialogClickModal: false,
          column: [
            {
              label: "统计日期",
              prop: "baltime",
              rules: [{
                required: true,
                message: "请输入统计日期",
                trigger: "blur"
              }]
            },
            {
              label: "应用领域",
              prop: "typeno",
              rules: [{
                required: true,
                message: "请输入应用领域",
                trigger: "blur"
              }]
            },
            {
              label:"发卡地:广州",
              children:[
                {
                  label:"CPU交易",
                  children:[
                    {
              label: "广州CPU卡普通消费卡数",
              prop: "gzcpunml",
              rules: [{
                required: true,
                message: "请输入广州CPU卡普通消费卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU卡15次后6折卡数",
              prop: "gzcpunmldis1",
              rules: [{
                required: true,
                message: "请输入广州CPU卡15次后6折卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU卡9折折扣卡数",
              prop: "gzcpunmldis2",
              rules: [{
                required: true,
                message: "请输入广州CPU卡9折折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU卡8折折扣卡数",
              prop: "gzcpunmldis3",
              rules: [{
                required: true,
                message: "请输入广州CPU卡8折折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU卡5折折扣卡数",
              prop: "gzcpunmldis4",
              rules: [{
                required: true,
                message: "请输入广州CPU卡5折折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU卡单笔跨优惠折扣卡数",
              prop: "gzcpunmldis5",
              rules: [{
                required: true,
                message: "请输入广州CPU卡单笔跨优惠折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU学生消费卡数",
              prop: "gzcpustd",
              rules: [{
                required: true,
                message: "请输入广州CPU学生消费卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU儿童全免卡数",
              prop: "gzcpuchd",
              rules: [{
                required: true,
                message: "请输入广州CPU儿童全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU残疾全免卡数",
              prop: "gzcpucrpf",
              rules: [{
                required: true,
                message: "请输入广州CPU残疾全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU残疾半免卡数",
              prop: "gzcpucrph",
              rules: [{
                required: true,
                message: "请输入广州CPU残疾半免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU老人全免卡数",
              prop: "gzcpueldf1",
              rules: [{
                required: true,
                message: "请输入广州CPU老人全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU老人半价卡数",
              prop: "gzcpueldh1",
              rules: [{
                required: true,
                message: "请输入广州CPU老人半价卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU新版老人全免卡数",
              prop: "gzcpueldf2",
              rules: [{
                required: true,
                message: "请输入广州CPU新版老人全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU新版老人半价卡数",
              prop: "gzcpueldh2",
              rules: [{
                required: true,
                message: "请输入广州CPU新版老人半价卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU外埠老人全免卡数",
              prop: "gzcpueldf3",
              rules: [{
                required: true,
                message: "请输入广州CPU外埠老人全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU外埠老人半价卡数",
              prop: "gzcpueldh3",
              rules: [{
                required: true,
                message: "请输入广州CPU外埠老人半价卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU军优全免证",
              prop: "gzcpumlt",
              rules: [{
                required: true,
                message: "请输入广州CPU军优全免证",
                trigger: "blur"
              }]
            },
            {
              label: "广州CPU旅游卡",
              prop: "gzcputrv",
              rules: [{
                required: true,
                message: "请输入广州CPU旅游卡",
                trigger: "blur"
              }]
            },

                  ]
                },


                {
                  label:"M1交易",
                  children:[
                    {
              label: "广州M1普通消费卡数",
              prop: "gzm1nml",
              rules: [{
                required: true,
                message: "请输入广州M1普通消费卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1卡15次后6折折扣卡数",
              prop: "gzm1nmldis1",
              rules: [{
                required: true,
                message: "请输入广州M1卡15次后6折折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1卡9折折扣卡数",
              prop: "gzm1nmldis2",
              rules: [{
                required: true,
                message: "请输入广州M1卡9折折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1卡8折折扣卡数",
              prop: "gzm1nmldis3",
              rules: [{
                required: true,
                message: "请输入广州M1卡8折折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1卡5折折扣卡数",
              prop: "gzm1nmldis4",
              rules: [{
                required: true,
                message: "请输入广州M1卡5折折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1卡单笔跨优惠折扣卡数",
              prop: "gzm1nmldis5",
              rules: [{
                required: true,
                message: "请输入广州M1卡单笔跨优惠折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1学生消费卡数",
              prop: "gzm1std",
              rules: [{
                required: true,
                message: "请输入广州M1学生消费卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1儿童全免卡数",
              prop: "gzm1chd",
              rules: [{
                required: true,
                message: "请输入广州M1儿童全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1残疾全免卡数",
              prop: "gzm1crpf",
              rules: [{
                required: true,
                message: "请输入广州M1残疾全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1残疾半免卡数",
              prop: "gzm1crph",
              rules: [{
                required: true,
                message: "请输入广州M1残疾半免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1老人全免卡数",
              prop: "gzm1eldf1",
              rules: [{
                required: true,
                message: "请输入广州M1老人全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1老人半价卡数",
              prop: "gzm1eldh1",
              rules: [{
                required: true,
                message: "请输入广州M1老人半价卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1新版老人全免卡数",
              prop: "gzm1eldf2",
              rules: [{
                required: true,
                message: "请输入广州M1新版老人全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1新版老人半价卡数",
              prop: "gzm1eldh2",
              rules: [{
                required: true,
                message: "请输入广州M1新版老人半价卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1外埠老人全免卡数",
              prop: "gzm1eldf3",
              rules: [{
                required: true,
                message: "请输入广州M1外埠老人全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1外埠老人半价卡数",
              prop: "gzm1eldh3",
              rules: [{
                required: true,
                message: "请输入广州M1外埠老人半价卡数",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1军优全免证",
              prop: "gzm1mlt",
              rules: [{
                required: true,
                message: "请输入广州M1军优全免证",
                trigger: "blur"
              }]
            },
            {
              label: "广州M1旅游卡",
              prop: "gzm1trv",
              rules: [{
                required: true,
                message: "请输入广州M1旅游卡",
                trigger: "blur"
              }]
            }

                  ]
                }
              ]
            },

            //发卡地全省的
            {
              label:"发卡地：全省",
              children:[
                {
                  label:"CPU交易",
                  children:[
                    {
              label: "全省CPU普通消费卡数",
              prop: "provcpunml",
              rules: [{
                required: true,
                message: "请输入全省CPU普通消费卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU15次后6折折扣卡数",
              prop: "provcpunmldis1",
              rules: [{
                required: true,
                message: "请输入全省CPU15次后6折折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU9折折扣卡数",
              prop: "provcpunmldis2",
              rules: [{
                required: true,
                message: "请输入全省CPU9折折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU8折折扣卡数",
              prop: "provcpunmldis3",
              rules: [{
                required: true,
                message: "请输入全省CPU8折折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU5折折扣卡数",
              prop: "provcpunmldis4",
              rules: [{
                required: true,
                message: "请输入全省CPU5折折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU单笔跨优惠折扣卡数",
              prop: "provcpunmldis5",
              rules: [{
                required: true,
                message: "请输入全省CPU单笔跨优惠折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU学生消费卡数",
              prop: "provcpustd",
              rules: [{
                required: true,
                message: "请输入全省CPU学生消费卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU儿童全免卡数",
              prop: "provcpuchd",
              rules: [{
                required: true,
                message: "请输入全省CPU儿童全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU残疾全免卡数",
              prop: "provcpucrpf",
              rules: [{
                required: true,
                message: "请输入全省CPU残疾全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU残疾半免卡数",
              prop: "provcpucrph",
              rules: [{
                required: true,
                message: "请输入全省CPU残疾半免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU老人全免卡数",
              prop: "provcpueldf1",
              rules: [{
                required: true,
                message: "请输入全省CPU老人全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU老人半价卡数",
              prop: "provcpueldh1",
              rules: [{
                required: true,
                message: "请输入全省CPU老人半价卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU新版老人全免卡数",
              prop: "provcpueldf2",
              rules: [{
                required: true,
                message: "请输入全省CPU新版老人全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU新版老人半价卡数",
              prop: "provcpueldh2",
              rules: [{
                required: true,
                message: "请输入全省CPU新版老人半价卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU外埠老人全免卡数",
              prop: "provcpueldf3",
              rules: [{
                required: true,
                message: "请输入全省CPU外埠老人全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU外埠老人半价卡数",
              prop: "provcpueldh3",
              rules: [{
                required: true,
                message: "请输入全省CPU外埠老人半价卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU军优全免证",
              prop: "provcpumlt",
              rules: [{
                required: true,
                message: "请输入全省CPU军优全免证",
                trigger: "blur"
              }]
            },
            {
              label: "全省CPU旅游卡",
              prop: "provcputrv",
              rules: [{
                required: true,
                message: "请输入全省CPU旅游卡",
                trigger: "blur"
              }]
            }

                  ]
                },

                //M1的
                {
                  label:"M1交易",
                  children:[
                    {
              label: "全省M1普通消费卡数",
              prop: "provm1nml",
              rules: [{
                required: true,
                message: "请输入全省M1普通消费卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1卡15次后6折折扣卡数",
              prop: "provm1nmldis1",
              rules: [{
                required: true,
                message: "请输入全省M1卡15次后6折折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1卡9折折扣卡数",
              prop: "provm1nmldis2",
              rules: [{
                required: true,
                message: "请输入全省M1卡9折折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1卡8折折扣卡数",
              prop: "provm1nmldis3",
              rules: [{
                required: true,
                message: "请输入全省M1卡8折折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1卡5折折扣卡数",
              prop: "provm1nmldis4",
              rules: [{
                required: true,
                message: "请输入全省M1卡5折折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1卡单笔跨优惠折扣卡数",
              prop: "provm1nmldis5",
              rules: [{
                required: true,
                message: "请输入全省M1卡单笔跨优惠折扣卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1学生消费卡数",
              prop: "provm1std",
              rules: [{
                required: true,
                message: "请输入全省M1学生消费卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1儿童全免卡数",
              prop: "provm1chd",
              rules: [{
                required: true,
                message: "请输入全省M1儿童全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1残疾全免卡数",
              prop: "provm1crpf",
              rules: [{
                required: true,
                message: "请输入全省M1残疾全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1残疾半免卡数",
              prop: "provm1crph",
              rules: [{
                required: true,
                message: "请输入全省M1残疾半免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1老人全免卡数",
              prop: "provm1eldf1",
              rules: [{
                required: true,
                message: "请输入全省M1老人全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1全省M1老人半价卡数",
              prop: "provm1eldh1",
              rules: [{
                required: true,
                message: "请输入全省M1全省M1老人半价卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1新版老人全免卡数",
              prop: "provm1eldf2",
              rules: [{
                required: true,
                message: "请输入全省M1新版老人全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1新版老人半价卡数",
              prop: "provm1eldh2",
              rules: [{
                required: true,
                message: "请输入全省M1新版老人半价卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1外埠老人全免卡数",
              prop: "provm1eldf3",
              rules: [{
                required: true,
                message: "请输入全省M1外埠老人全免卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1外埠老人半价卡数",
              prop: "provm1eldh3",
              rules: [{
                required: true,
                message: "请输入全省M1外埠老人半价卡数",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1军优全免证",
              prop: "provm1mlt",
              rules: [{
                required: true,
                message: "请输入全省M1军优全免证",
                trigger: "blur"
              }]
            },
            {
              label: "全省M1旅游卡",
              prop: "provm1trv",
              rules: [{
                required: true,
                message: "请输入全省M1旅游卡",
                trigger: "blur"
              }]
            }

                  ]
                }

              ]
            },
            
          ]
        },
        data: []
      };
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.simp105003_add, false),
          viewBtn: this.vaildData(this.permission.simp105003_view, false),
          delBtn: this.vaildData(this.permission.simp105003_delete, false),
          editBtn: this.vaildData(this.permission.simp105003_edit, false)
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
    methods: {
      rowSave(row, done, loading) {
        add(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          window.console.log(error);
        });
      },
      rowUpdate(row, index, done, loading) {
        update(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          console.log(error);
        });
      },
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(row.id);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      },
      handleDelete() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(this.ids);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crud.toggleSelection();
          });
      },
      beforeOpen(done, type) {
        if (["edit", "view"].includes(type)) {
          getDetail(this.form.id).then(res => {
            this.form = res.data.data;
          });
        }
        done();
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        this.loading = true;
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
      }
    }
  };
</script>

<style>
</style>
